package xiaomi;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-9-1下午 07:38
 */
public class Test2 {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        final int i = lastRemaining(n, 3);
        System.out.println(i);
    }

    public static int lastRemaining(int n, int m) {
        ArrayList<Integer> list = new ArrayList<>(n);
        for (int i = 1; i <= n; i++) {
            list.add(i);
        }
        int idx = 0;
        while (n > 1) {
            idx = (idx + m - 1) % n;
            list.remove(idx);
            n--;
        }
        return list.get(0);
    }
}
